package cao.oschina.bean;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.List;

/**
 * 赞
 * <p/>
 * Created by Haidy on 15/4/4.
 */
public class Like {

    public String name;
    public String uid;
    public String portrait;

    public static List<Like> parser(NodeList nodeList) {
        List<Like> likeList = new ArrayList<>();
        for (int i = 0; i < nodeList.getLength(); i++) {
            NodeList childNodes = nodeList.item(i).getChildNodes();
            Like like = new Like();
            for (int j = 0; j < childNodes.getLength(); j++) {
                Node childNode = childNodes.item(j);
                switch (childNode.getNodeName()) {
                    case "name":
                        like.name = childNode.getFirstChild().getNodeValue();
                        break;
                    case "uid":
                        like.uid = childNode.getFirstChild().getNodeValue();
                        break;
                    case "portrait":
                        if (childNode.getFirstChild() != null) {
                            like.portrait = childNode.getFirstChild().getNodeValue();
                        }
                        break;
                }
            }
            if (like.uid != null) {
                likeList.add(like);
            }
        }
        return likeList;
    }
}
